

<?php
//Name: Admin.php
//Purpose: This script is for administrators to view all users 
//CreateDate: 10/01/12
//check if user is admin, create session var to declare if is admin
session_name('login');
session_start();
if($_SESSION['isAdmin'] == false)
{
	header("location: /home.php");
	exit;
}

include 'util.php';

$dbConnection = getMySqlConnection();

$query ="SELECT * FROM person;";

$result = $dbConnection->query($query);

$numberOfUsers = $result->num_rows;

//display all all users info

//dispaly total users

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
	<head>
		<script src="javascript/tcaparrel.js" type="text/javascript"></script>
		<link rel="StyleSheet" href="css/tcaparrel.css" type="text/css">
		<link rel="StyleSheet" href="css/header.css" type="text/css">
	</head>

	<body class="productPage">
	<div class="contentWrapper">
		<div class="header">
		<?php 
		session_name('login');
		session_start();
		if(isset($_SESSION['username']))
		{
			include('loggedInUserHeader.php');
		}
		else
		{
			include ('loginformheader.php');
		}
		?>
		</div>
		
		<div class="menubarContentWrapper">
			<div class="menubar">
				<div class="menuItem" onclick="sweatshirts_click()"><label style="cursor: inherit">SweatShirts</label></div>
				<div class="menuItem" onclick="hats_click()"><label style="cursor: inherit">Hats</label></div>
				<div class="menuItem" onclick="tshirts_click()"><label style="cursor: inherit">T-Shirts</label></div>
				<div class="menuItem" onclick="pants_click()"><label style="cursor: inherit">Pants</label></div>
			</div>
		</div>
		
		<div class="adminContainer">
			<h1>Admin</h1>
			<div class="allUsers">
				Total Number of Users: <?php echo $numberOfUsers; ?>
			</div>
			<a href="allOrders.php">View All Orders</a>
			
			<a href="productcrud.php" >Product Update</a>
				<table class="allUsers">
					<tr>
						<th>Username</th>
						<th>Frist Name</th>
						<th>Last Name</th>
						<th>DOB</th>
						<th>Gender</th>
						<th>Email</th>
						<th>Admin</th>
						<th>Address</th>
						<th>City</th>
						<th>State</th>
						<th>Zip</th>
					</tr>
					
				<?php 
				
					while($userResult = $result->fetch_assoc())
					{
						$userId = $userResult['person_id'];
						$username = $userResult['username'];
						$firstName = $userResult['first_name'];
						$lastName = $userResult['last_name'];
						$dob = $userResult['dob'];
						$gender = $userResult['gender'];
						$email = $userResult['email'];
						$admin = $userResult['admin_ind'];
						$address = $userResult['street_address'];
						$city = $userResult['city'];
						$state = $userResult['state'];
						$zip = $userResult['zip'];
						echo "
					<tr>
						<td class='allUsers'>$username</td>
						<td class='allUsers'>$firstName</td>
						<td class='allUsers'>$lastName</td>
						<td class='allUsers'>$dob</td>
						<td class='allUsers'>$gender</td>
						<td class='allUsers'>$email</td>
						<td class='allUsers'>$admin</td>
						<td class='allUsers'>$address</td>
						<td class='allUsers'>$city</td>
						<td class='allUsers'>$state</td>
						<td class='allUsers'>$zip</td>
						<td>
							<form action='editUser.php' method='post'>
								<input type='submit' name='editUser' value='Edit User' />
								<input type='hidden' name='userToEditId' value='$userId' />
							</form>
						</td>
					</tr>
							";
					}
				?>
				</table>
		</div>
		
		<div class="footer"></div>
		</div>
	</body>

</html>